var clientcache = {prefix:"clientcache_"}

clientcache.getval = function (keyfield,refresh) {
  var app =getApp();
  keyfield=this.prefix +keyfield;  
  return new Promise(function (resolve) {
    if (!refresh && app.globalData.clientcache[keyfield]) {
      resolve(app.globalData.clientcache[keyfield])
    }
    wx.getStorage({
      key: keyfield,
      success: function (res) {

        resolve(res.data)
      },
      fail:function(){
        resolve(null)
      }
    })
  })
}
 
clientcache.setval=function(keyfield,val){
  keyfield=   this.prefix +keyfield
  var app=getApp()
  app.globalData.clientcache[keyfield] 
  wx.setStorage({
    key:keyfield,
    data:val
  })
}

module.exports = clientcache